﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Collections.Specialized;
using System.IO;
using System.Diagnostics;

namespace GIVisualEditor.TaskModel
{
    public class ExecuteProcessTask : ITask
    {

        public ExecuteProcessTask()
        {

        }


        #region ITask Members

        public void Execute(NameValueCollection oContext)
        {
            if (oContext != null && oContext[TaskFactory.VALUE_KEY_NAME] != null)
            {
                string executablePath = EnvionmentVariables.ResolveFolderOrFilePath( oContext[TaskFactory.VALUE_KEY_NAME] );
                if (File.Exists(executablePath))
                {
                    Process oProcess = new Process();
                    oProcess.StartInfo.FileName = "notepad.exe";
                    oProcess.StartInfo.Arguments = "ProcessStart.cs";

                    oProcess.Start();
                    if (oContext["wait"] != null && (oContext["wait"] == "yes" ||oContext["wait"] == "true" ))
                    {
                        oProcess.WaitForExit();
                    }
                }

            }
        }

        #endregion
    }
}
